/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csvreader.view;

import csvreader.controller.AddController;
import csvreader.controller.ResetText;
import csvreader.model.Contact;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author User
 */
public class AddPanel extends javax.swing.JDialog {

    private AddController ac;
    
    public AddPanel(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        ac = new AddController(this, (MainFrame) this.getParent());
        initComponents();
        setResizable(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        batalButton = new javax.swing.JButton();
        buttonTambah = new javax.swing.JButton();
        textFieldTelepon3 = new javax.swing.JTextField();
        textFieldTelepon2 = new javax.swing.JTextField();
        textFieldTelepon1 = new javax.swing.JTextField();
        textFieldNama = new javax.swing.JTextField();
        labelNama = new javax.swing.JLabel();
        labelTelepon1 = new javax.swing.JLabel();
        labelTelepon2 = new javax.swing.JLabel();
        labelTelepon3 = new javax.swing.JLabel();
        labelEmail = new javax.swing.JLabel();
        textFieldEmail = new javax.swing.JTextField();
        textFieldKeterangan = new javax.swing.JTextField();
        labelKeterangan = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        batalButton.setText("Batal");
        batalButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batalButtonActionPerformed(evt);
            }
        });

        buttonTambah.setText("Tambah");
        buttonTambah.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonTambahActionPerformed(evt);
            }
        });

        labelNama.setText("Nama :");

        labelTelepon1.setText("Telepon 1 :");

        labelTelepon2.setText("Telepon 2 :");

        labelTelepon3.setText("Telepon 3 :");

        labelEmail.setText("Email :");

        labelKeterangan.setText("Keterangan :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 111, Short.MAX_VALUE)
                .addComponent(buttonTambah)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(batalButton)
                .addGap(12, 12, 12))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelTelepon2)
                    .addComponent(labelTelepon1)
                    .addComponent(labelNama)
                    .addComponent(labelTelepon3)
                    .addComponent(labelEmail)
                    .addComponent(labelKeterangan))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(textFieldNama)
                    .addComponent(textFieldTelepon1, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                    .addComponent(textFieldEmail)
                    .addComponent(textFieldTelepon3)
                    .addComponent(textFieldTelepon2, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                    .addComponent(textFieldKeterangan))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textFieldNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(labelNama, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldTelepon1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTelepon1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldTelepon2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTelepon2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldTelepon3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTelepon3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelEmail)
                    .addComponent(textFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelKeterangan)
                    .addComponent(textFieldKeterangan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonTambah)
                    .addComponent(batalButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void batalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batalButtonActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_batalButtonActionPerformed

    private void buttonTambahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTambahActionPerformed
        ac.submit();
    }//GEN-LAST:event_buttonTambahActionPerformed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton batalButton;
    private javax.swing.JButton buttonTambah;
    private javax.swing.JLabel labelEmail;
    private javax.swing.JLabel labelKeterangan;
    private javax.swing.JLabel labelNama;
    private javax.swing.JLabel labelTelepon1;
    private javax.swing.JLabel labelTelepon2;
    private javax.swing.JLabel labelTelepon3;
    private javax.swing.JTextField textFieldEmail;
    private javax.swing.JTextField textFieldKeterangan;
    private javax.swing.JTextField textFieldNama;
    private javax.swing.JTextField textFieldTelepon1;
    private javax.swing.JTextField textFieldTelepon2;
    private javax.swing.JTextField textFieldTelepon3;
    // End of variables declaration//GEN-END:variables

    private void cekInput(String keyChar) {
        if(!checkChar(keyChar)){
            JOptionPane.showMessageDialog(labelTelepon1, "Nama Hanya Mengandung Huruf", "error", JOptionPane.ERROR_MESSAGE);
            ResetText.resetJTextField(this);
        }
    }

    private boolean checkChar(String keyChar) {
        if(keyChar.matches("[a-zA-Z]")){
            return true;
        }else{
            return false;
        }
    }

    public javax.swing.JTextField getTextFieldEmail() {
        return textFieldEmail;
    }

    public javax.swing.JTextField getTextFieldKeterangan() {
        return textFieldKeterangan;
    }

    public javax.swing.JTextField getTextFieldNama() {
        return textFieldNama;
    }

    public javax.swing.JTextField getTextFieldTelepon1() {
        return textFieldTelepon1;
    }

    public javax.swing.JTextField getTextFieldTelepon2() {
        return textFieldTelepon2;
    }
    
    public javax.swing.JTextField getTextFieldTelepon3() {
        return textFieldTelepon3;
    }
}
